<template>
	<!-- 地址管理 -->
	<view>
		<scroll-view class="address " scroll-y="true" v-if="addresslist.length != 0">
			<view v-for="(item,index) in addresslist" :key="index" class="bg-white " @click="navige(item)">
				<view class="name_phone">
					<text class="name">{{item.name}}</text>
					<text class="phone">{{item.phone}}</text>
				</view>
				<view class="_address_">{{item.province+item.city+item.district+item.address}}</view>
				<view class="solid">
					
				</view>
				<view class="mrdz flex-cb">
					<text>默认地址</text>
					<image src="/static/s1.png" mode=""  v-if="item.is_default"  @click.stop="handleitem(item.id)"></image>
					<image src="/static/s2.png" mode=""  v-else @click.stop="handleitem(item.id)"></image>
				</view>
			</view>
		</scroll-view>
		<nodata v-else />
		<navigator url="../Addaddress" class="button flex-c">添加收货地址</navigator>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ischecked:0,
				addresslist:[],
				goods_id:null
			};
		},
		onLoad(e) {
			this.goods_id = e.goods_id
		},
		onShow() {
			this.getdata()
		},
		methods:{
			handleitem(id){
				this.$api.defaultAddress({},id,true).then(res=>{
					console.log(res);
					this.getdata()
				})
			},
			navige(e){
				if(this.goods_id){
					this.$api.express_order_change_address({},this.goods_id,e.id,1).then(res=>{
						if(res.code == 200001){
							uni.navigateBack({
								delta: 1,
								animationDuration: 500
							})
						}
					})
				}else{
					uni.navigateTo({
						url:'../Addaddress?e=' + JSON.stringify(e)
					})
				}
			},
			getdata(){
				this.$api.addresses_list().then(res=>{
					if(res.code == 200001){
						this.addresslist = res.data
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.address{
	margin: 1rpx;
	height: calc(100vh - 100rpx);
	overflow: hidden;
	.bg-white{
		height: 267rpx;
		margin-bottom: 10rpx;
		padding: 34rpx 32rpx 0 38rpx;
		.name_phone{
			margin-bottom: 29rpx;
			.name{
				font-size: 36rpx;
				color: #2F2F2F;
				font-weight: bold;
			}
			.phone{
				font-size: 30rpx;
				margin-left: 22rpx;
				color: #969696;
			}
		}
		._address_{
			font-size: 28rpx;
			color: #333;
			margin-bottom: 27rpx;
		}
		.mrdz{
			height: 86rpx;
		}
	}
}
.button{
	position: fixed;
	left: 30rpx;
	bottom: 30rpx;
	width: 690rpx;
	height: 80rpx;
	border-radius: 80rpx;
	background: #1CD699;
	font-size: 30rpx;
	color: #FFF;
}
image{
		width: 104rpx;height: 60rpx;
	}
</style>
